#ifndef __JSON_PARSE_H__
#define __JSON_PARSE_H__

#include <stdbool.h>
#include <stdio.h>

#define JSONPATH_BUFFER_SIZE 100        //jsonpath缓存大小
#define JSONPATH_CASE_INSENSITIVE 1      //不分大小写

#define _JSON_PARSE_AUTO_TYPE(var, p) _Generic((var),               \
    bool: var = JsonPraseBool(p),                                   \
    signed char: var = (signed char)JsonPraseInt(p),                \
    unsigned char: var = (unsigned char)JsonPraseInt(p),            \
    signed short: var = (signed short)JsonPraseInt(p),              \
    unsigned short: var = (unsigned short)JsonPraseInt(p),          \
    signed int: var = JsonPraseInt(p),                              \
    unsigned int: var = (unsigned int)JsonPraseInt(p),              \
    signed long: var = (signed long)JsonPraseInt(p),                \
    unsigned long: var = (unsigned long)JsonPraseInt(p),            \
    signed long long: var = (signed long long)JsonPraseInt(p),      \
    unsigned long long: var = (unsigned long long)JsonPraseInt(p),  \
    float: var = (float)JsonPraseDouble(p),                         \
    double: var = JsonPraseDouble(p),                               \
    default: printf("error Invalid type!!!\r\n")                    \
    )

/* cJSON Types: */
typedef enum{
    JSON_INVALID,
    JSON_BOOL,
    JSON_NULL,
    JSON_NUMBER,
    JSON_STRING,
    JSON_ARRAY,
    JSON_OBJECT,
}json_type_t;

char* JsonPath(char *str, char *json_path, ...);//使用jsonpath查找对应的值
char* JsonPathCheck(char *str,json_type_t json_type,char *format, ...);//JsonPath带检查类型功能的版本
json_type_t JsonGetType(char *str);//查询值类型
int JsonGetItemNumsInArray(char *str);//查询数组的项数
double JsonPraseDouble(char *str);//解析double的值
int JsonPraseInt(char *str);//解析int类型的值
bool JsonPraseBool(char *str);//解析bool类型的值
int JsonPraseStr(char *str,char *buf,unsigned int buf_size);//解析string类型的值

// #define example 1
#ifdef example
void main(void);
#endif

#endif
